# -*- coding:utf-8 -*-

import socket
import urllib.request
import urllib.parse
import urllib.error

# get method
# def getHtml(url):
#     response = urllib.request.urlopen(url)
#
#     html = response.read().decode('utf-8')
#
#     return html

# html = getHtml("http://www.jianshu.com")

# print(html)

# post method

data = bytes(urllib.parse.urlencode({'world':'hello'}), encoding='utf-8')
response = urllib.request.urlopen('https://httpbin.org/post',data=data)

print(response.read().decode('utf-8'))

# # try:
# response = urllib.request.urlopen('https://python.org/')
#
# print(response.status)
# print(response.getheaders())
# print(response.getheader('Server'))
#
# # except urllib.error.URLError as e:
# #     if  isinstance(e.reason, socket.timeout):
# #         print('TIME OUT')


